using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Jbe.TestSuite.TestDevice.Manager.Interface.Services;

namespace Jbe.TestSuite.TestDevice.Manager.Mapper
{
    public static class ControlViewMapper
    {
        public static ListViewItem ToListViewItem(IControlView device)
        {
            return new DeviceListViewItem(device);
        }

        public static IControlView FromListViewItem(ListViewItem listViewItem)
        {
            DeviceListViewItem deviceListViewItem = (DeviceListViewItem)listViewItem;
            return deviceListViewItem.Device;
        }

        private class DeviceListViewItem : ListViewItem
        {
            private IControlView device;

            public IControlView Device
            {
                get { return device; }
            }

            public DeviceListViewItem(IControlView device)
            {
                this.device = device;
                Name = device.Name;
                Text = device.Name;
                Group = new ListViewGroup(device.Device.ProfileName);

                SubItems.Add(new ListViewSubItem(this, "     " + device.Device.ProductName));
                SubItems.Add(new ListViewSubItem(this, "     " + device.Device.Manufacturer));
            }
        }
    }
}
